//
//  HouseLoanViewController.m
//  SourceCodeRead
//
//  Created by Kael on 2018/7/1.
//  Copyright © 2018年 Kael. All rights reserved.
//

#import "HouseLoanViewController.h"

#import "HouseLoanModel.h"

@interface HouseLoanViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) HouseLoanModel *houseLoanInterest;

@property (nonatomic, strong) HouseLoanModel *houseLoanPrincipal;



@end

@implementation HouseLoanViewController

#pragma mark - **************** 初始化操作
- (void)initBaseData {
    
}

- (void)initBaseView {
    self.view.backgroundColor = [UIColor whiteColor];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initBaseData];
    [self initBaseView];
    
    
    _houseLoanInterest = [[HouseLoanModel alloc] init];
    [_houseLoanInterest setPropsTotalPrice:@(1200000) loanAmount:@(900000) mortgageYears:@(30) interest:@(0.045/12.0) repaymentMethod:RepayMentMethodEqualInterest];
    
    
    
    _houseLoanPrincipal = [[HouseLoanModel alloc] init];
    [_houseLoanPrincipal setPropsTotalPrice:@(1200000) loanAmount:@(900000) mortgageYears:@(30) interest:@(0.045/12.0) repaymentMethod:RepayMentMethodEqualPrincipal];
    
    
//    NSLog(@"%@",_houseLoanPrincipal.monthInterestsArr);
    
    [self.view addSubview:self.tableView];
    self.tableView.frame = self.view.bounds;
  
}

#pragma mark lazy loading...
-(UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}

#pragma tableView--delegate
#pragma tableView
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _houseLoanPrincipal.monthRepaymentsArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identify = @"cellIdentify";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identify];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identify];
    }
    NSNumber *value = _houseLoanPrincipal.monthRepaymentsArr[indexPath.row];
    cell.textLabel.text = [NSString stringWithFormat:@"%@",value];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}



-(void)testFunction{
    /**
     最近选中的cell 滚动到  指定位置 ：
     UITableViewScrollPositionNone,
     UITableViewScrollPositionTop,
     UITableViewScrollPositionMiddle,
     UITableViewScrollPositionBottom
     */
    [self.tableView scrollToNearestSelectedRowAtScrollPosition:UITableViewScrollPositionTop animated:YES];
    
    /** 滚动指定段的指定row  到 指定位置 */
    [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
    
    /** 通过设置contentOffset的方式滚动tableView到指定的位置 */
    [self.tableView setContentOffset:CGPointMake(0, 0) animated:YES];
    
    /** 指定section的最顶部的rect */
    [self.tableView rectForSection:0];
    
    /** 指定cell的rect */
    [self.tableView rectForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
    
    /** sectionHeader 的rect */
    [self.tableView rectForHeaderInSection:0];
    
    /** sectionFooter 的rect */
    [self.tableView rectForFooterInSection:0];
    
    // ---------------------------
    
    /** self.tabView 上的某个区域 相对于 其父视图的rect */
    [self.tableView convertRect:CGRectMake(0, 0, 100, 100) toView:self.tableView.superview];
    
    /** self.view 上的视图 self.tableView 相对于某个rect的rect */
    [self.tableView convertRect:CGRectMake(0, 0, 100, 100) fromView:self.view];
    
    /** 滚动到顶部 */
    [self.tableView setScrollsToTop:YES];
    
    /** 让指定区域滚动到可视区域，如果已经在可视区域 则该方法无效 */
    [self.tableView scrollRectToVisible:CGRectMake(0, 0, 100, 100) animated:YES];
 
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
